package com.spring.springboot.Mapper;

import com.spring.springboot.pojo.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author lking
 * @date 2019/11/29 20:20
 **/
@Mapper
//该注解是解决 IDEA mapper注入时显示 could not autowire, no beans type of
@Component(value = "userMapper")
public interface UserMapper {

    @Select("SELECT * FROM user")
    List<User> findAll();

    @Select("select * from user where id=#{id}")
    @Results({
            @Result(property = "name", column = "name"),
            @Result(property = "age", column = "age")
    })
    User getUsertById(int id);

    @Delete("delete from user where id=#{id}")
    int deleteUserById(int id);


    @Insert("INSERT INTO user(id,name, age) VALUES (#{id},#{name}, #{age})")
    int insertUser( User user);

    @Update("update user set name=#{name},age=#{age} where id=#{id}")
    int updateUser(User user);
}
